package com.panshi.controller.qa;

import com.panshi.api.IReplyApi;
import com.panshi.vo.qa.DataResultQA;
import com.panshi.vo.qa.Pages;
import com.panshi.vo.qa.Reply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@CrossOrigin//跨域
public class ReplyController {

    @Autowired
    IReplyApi replyApi;

    /*Reply(回答)*/

    /**
     * 分页查询
     * @param pages
     * @return
     */
    @PostMapping("/reply/inquirePages")
    @ResponseBody
    DataResultQA<Pages<Reply>> inquirePagesReply(@RequestBody Pages pages){
        DataResultQA<Pages<Reply>> dataResultQA = replyApi.inquirePagesReply(pages);
        return dataResultQA;
    }

    /**
     * 查询总记录数
     * @param pages
     * @return
     */
    @GetMapping("/reply/inquireSum")
    @ResponseBody
    DataResultQA<Integer> inquireReplySum(@RequestParam Pages pages){
        DataResultQA<Integer> dataResultQA = replyApi.inquireReplySum(pages);
        return dataResultQA;
    }

    /**
     * 通过id查询回答
     * @param id
     * @return
     */
    @PostMapping("/reply/inquireById/{id}")
    @ResponseBody
    DataResultQA<Reply> inquireByIdReply(@PathVariable int id){
        DataResultQA<Reply> dataResultQA = replyApi.inquireByIdReply(id);
        return dataResultQA;
    }

    /**
     * 点赞总数加一
     * @param id
     * @return
     */
    @GetMapping("/reply/praiseSumAnd1/{id}")
    @ResponseBody
    DataResultQA praiseSumAnd1_Reply(@PathVariable int id){
        DataResultQA dataResultQA = replyApi.praiseSumAnd1_Reply(id);
        return dataResultQA;
    }

    /**
     * 点赞总数减一
     * @param id
     * @return
     */
    @GetMapping(value = "/reply/praiseSumSubtract1/{id}")
    @ResponseBody
    DataResultQA praiseSumSubtract1(@PathVariable int id){
        DataResultQA dataResultQA = replyApi.praiseSumSubtract1_Reply(id);
        return dataResultQA;
    }

    /**
     * 点踩总数加一
     * @param id
     * @return
     */
    @GetMapping("/reply/trampleSumAnd1/{id}")
    @ResponseBody
    DataResultQA trampleSumAnd1_Reply(@PathVariable int id){
        DataResultQA dataResultQA = replyApi.trampleSumAnd1_Reply(id);
        return dataResultQA;
    }

    /**
     * 点踩总数减一
     * @param id
     * @return
     */
    @GetMapping(value = "/reply/trampleSumSubtract1/{id}")
    @ResponseBody
    DataResultQA trampleSumSubtract1(@PathVariable int id){
        DataResultQA dataResultQA = replyApi.trampleSumSubtract1_Reply(id);
        return dataResultQA;
    }

    /**
     * 删除(标记删除)
     * @param id
     * @return
     */
    @GetMapping("/reply/delete/{id}")
    @ResponseBody
    DataResultQA deleteReply(@PathVariable int id){
        DataResultQA dataResultQA = replyApi.deleteReply(id);
        return dataResultQA;
    }
}
